<?php
class AllFieldValuesIterator extends IteratorIterator {
	
	public function __construct(ArrayObject $values) {
		parent::__construct($values->getIterator());
	}
	
	private function currentFieldValue() {
		$fieldValue = parent::current();
		if($fieldValue !== false) {
			$field = $fieldValue->field;
			// Current timestamp CI
			if(!isset($fieldValue))
				if($field->isAI || strtoupper($field->default) == 'CURRENT_TIMESTAMP')
					$value = null;
				else
					$value = $fieldValue->field->default;
			else
				$value = $fieldValue->value;
			return $value;
		}
	}
	
	public function toArray($useKeys = true) {
		return iterator_to_array($this, $useKeys);
	}
	
	public function __get($name) {
		if($name == 'types') {
			$types = '';
			foreach($this as $fieldValue)
				$types .= parent::current()->field->getStatementType();
			return $types;
		}
	}
	
	public function current() {
		if(parent::valid())
			return $this->currentFieldValue();
		else
			return false;
	}
	
	public function next() {
		parent::next();
		if(parent::valid())
			return $this->currentFieldValue();
		else
			return false;
	}
}
?>